"use strict";
cc._RF.push(module, '0cf8bUSii9BoqCYX2UowsTx', '__preview');
// preview/__preview.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var NewClass = /** @class */ (function (_super) {
    __extends(NewClass, _super);
    function NewClass() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._scaleBase = 1;
        _this._isDrag = false;
        return _this;
    }
    NewClass.prototype.start = function () {
        var tipNode = cc.find("Canvas/tip");
        if (tipNode && !tipNode.active) {
            tipNode.active = true;
        }
        var scaleSliderNode = cc.find("Canvas/scaleSlider");
        if (scaleSliderNode && scaleSliderNode.active) {
            scaleSliderNode.active = false;
        }
        var lrSliderNode = cc.find("Canvas/lrSlider");
        if (lrSliderNode && lrSliderNode.active) {
            lrSliderNode.active = false;
        }
        var ubSliderNode = cc.find("Canvas/ubSlider");
        if (ubSliderNode && ubSliderNode.active) {
            ubSliderNode.active = false;
        }
        var view = cc.find("Canvas/view");
        if (view) {
            view.on(cc.Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
            view.on(cc.Node.EventType.MOUSE_MOVE, this.onMouseMove, this);
            view.on(cc.Node.EventType.MOUSE_WHEEL, this.onMouseWheel, this);
        }
    };
    NewClass.prototype.onMouseDown = function (e) {
        var btn = e.getButton();
        if (btn == null || btn == undefined)
            return;
        switch (btn) {
            case cc.Event.EventMouse.BUTTON_RIGHT:
                this._isDrag = true;
                break;
            case cc.Event.EventMouse.BUTTON_LEFT:
                this._isDrag = false;
                var model = cc.find('Canvas/modelRoot/model');
                if (model) {
                    var pos = e.getLocation();
                    var viewSize = cc.view.getVisibleSize();
                    pos.x -= viewSize.width / 2;
                    pos.y -= viewSize.height / 2;
                    model.setPosition(pos);
                }
                break;
        }
    };
    NewClass.prototype.onMouseMove = function (e) {
        if (!this._isDrag)
            return;
        var model = cc.find('Canvas/modelRoot/model');
        if (model) {
            var pos = e.getLocation();
            var viewSize = cc.view.getVisibleSize();
            pos.x -= viewSize.width / 2;
            pos.y -= viewSize.height / 2;
            model.setPosition(pos);
        }
    };
    NewClass.prototype.onMouseWheel = function (e) {
        var offsetY = e.getScrollY();
        var model = cc.find('Canvas/modelRoot/model');
        if (model) {
            var offset = offsetY / 5;
            var scale = model.scale + offset;
            if (scale > 1 && scale < 1002) {
                model.scale = scale;
            }
        }
    };
    NewClass.prototype.onSlider = function (s) {
        var scale = s.progress;
        var diff = scale - 0;
        var factor = (diff / 0.001);
        var model = cc.find('Canvas/modelRoot/model');
        if (model) {
            model.scale = this._scaleBase + factor;
        }
        var scNode = cc.find('Canvas/scaleSlider/label');
        if (scNode) {
            var label = scNode.getComponent(cc.Label);
            label.string = "scale * " + Math.round(this._scaleBase + factor);
        }
    };
    NewClass.prototype.onLRSlider = function (s) {
        var scale = s.progress;
        var diff = scale - 0.5;
        var factor = 360;
        var model = cc.find('Canvas/modelRoot/model');
        if (model) {
            model.rotationY = factor * diff;
        }
        var lrNode = cc.find('Canvas/lrSlider/label');
        if (lrNode) {
            var label = lrNode.getComponent(cc.Label);
            label.string = Math.round(factor * diff) + "°";
        }
    };
    NewClass.prototype.onUBSlider = function (s) {
        var scale = s.progress;
        var diff = scale - 0.5;
        var factor = 360;
        var model = cc.find('Canvas/modelRoot/model');
        if (model) {
            model.rotationX = factor * diff;
        }
        var lrNode = cc.find('Canvas/ubSlider/label');
        if (lrNode) {
            var label = lrNode.getComponent(cc.Label);
            label.string = Math.round(factor * diff) + "°";
        }
    };
    NewClass.prototype.onEditBoxDid = function (e) {
        var str = e.string;
        if (!str || str.length <= 0)
            return;
        var v = parseInt(str);
        if (v < 0)
            return;
        var model = cc.find('Canvas/modelRoot/model');
        if (model) {
            model.scale = v;
        }
    };
    NewClass = __decorate([
        ccclass
    ], NewClass);
    return NewClass;
}(cc.Component));
exports.default = NewClass;

cc._RF.pop();